# 通过Python核心模块里的os.path相关方法获取目录和文件属性
import os

# coding = utf-8
# 获取当前工作目录
path1 = os.path.abspath("D:\\D21_code\\python\\py-study")
print(path1)

# 获取文件是否存在
print(os.path.exists("D:\\D21_code\\python\\py-study"))
print(os.path.exists("D:\\D21_code\\python\\py-study2"))
print(os.path.exists("D:\\D21_code\\python\\py-study\\tex.text"))

# 返回文件名，路径名
print(os.path.basename("D:\\D21_code\\python\\py-study\\tex.text"))
print(os.path.dirname("D:\\D21_code\\python\\py-study\\tex.text"))

# 判断该路径是否是文件、是否是路径
print(os.path.isfile("D:\\D21_code\\python\\py-study\\tex.text"))
print(os.path.isdir("D:\\D21_code\\python\\py-study\\tex.text"))

# 拼接路径,返回元组形式（路径，文件名）
print(os.path.split("D:\\D21_code\\python\\py-study"))

# 打开文件,r只读模式，也是默认模式；w只写模式
file = open("D:/D21_code/python/py-study/tex2.text", mode='r', encoding="utf-8")
print(file.read())
file.close()
print("******************")
# 逐行读取文件
file = open("D:/D21_code/python/py-study/tex2.text", mode='r', encoding="utf-8")
for line in file:
    print(line)

file.close()
